﻿using System;
using System.ServiceProcess;

namespace EasyBackup.Utils
{
    static class BackupService
    {
        public static void Start()
        {
            try
            {
                using (ServiceController service = new ServiceController("Easy Backup Service"))
                {                                        
                    TimeSpan timeout = TimeSpan.FromMilliseconds(1000 * 1);
                    service.Start();
                    service.WaitForStatus(ServiceControllerStatus.Running, timeout);                    
                }
            }
            catch
            {
            }
        }

        public static void Stop()
        {
            try
            {
                using (ServiceController service = new ServiceController("Easy Backup Service"))
                {                    
                    TimeSpan timeout = TimeSpan.FromMilliseconds(1000 * 1);
                    service.Stop();
                    service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);                    
                }
            }
            catch
            {
            }
        }

        public static void Restart()
        {
            BackupService.Stop();
            BackupService.Start();
        }
    }
}
